var time = 0;
var NodeSet = require("./NodeSet");

var Distance = require("../lib/distances");

var f = new NodeSet(8);
var t = new NodeSet(8);

f.randInit();
t.randInit();
var allPoint = [].concat(f.nodeArr, t.nodeArr)

var scrand = require("arrayhelp/rand-lib/sumConservation.rand.js");
var tranFrom = scrand.sumConservatioRand(f.nodeArr.length);


var tranTo = scrand.sumConservatioRand(t.nodeArr.length);

tranFrom.fill(1/f.nodeArr.length);
tranTo.fill(1/t.nodeArr.length);

var twFunc = require("arrayhelp/tran.weigth")
var arrCount = require("arrayhelp/matrix2Sum")
var distance = Distance.get2Distances(f.nodeArr, t.nodeArr);
// var weigth = twFunc(tranFrom, tranTo, distance)
global.wi = {}
function draw() {
	distance = Distance.get2Distances(f.nodeArr, t.nodeArr);
	var weigth = twFunc(tranFrom, tranTo, distance);
	// global.weigth00 = weigth
	global.wi.distance = distance;
	global.wi.weigth = weigth;
	// console.log(arrCount.arrSum(arrCount.matrix2SumCol(weigth)))

	plot.clean()
	plot.drawNodeSet(f.nodeArr, "green");
	plot.drawNodeSet(t.nodeArr);
	for (var i = 0, len1 = f.nodeArr.length; i < len1; i++) {
		for (var j = 0, len2 = t.nodeArr.length; j < len2; j++) {
			plot.line(f.nodeArr[i], t.nodeArr[j], getColor(weigth[i][j]));
		}
	}
}

var canvasMv = require("../nodeSet/canvasMv")
var CanvasDom = document.querySelector("#myCanvas");
var Plot = require("../Plot");
// @ts-ignore
var plot = new Plot.Plot(CanvasDom);
canvasMv(plot.container, allPoint, draw)

draw()

function getColor(num) {
	var str = Math.floor(num * 255 * 3).toString(16).padStart(2, "0")
	return "#" + str + "0000"
}

global.wi = {
	plot, require, draw
}